package com.liz.test_old;

import java.sql.*;
import java.util.Scanner;

public class Text_update {
    public static void main(String[] args) {
        String jdbcdrive = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/bylianxi";
        String username = "root";
        String userpassword = "Au7989l";
        Connection conn = null;
        PreparedStatement ps = null;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个编号");
        String  m = sc.nextLine();
        System.out.println("请输入要修改人的工资");
        double sal = sc.nextDouble();
        try {
            Class.forName(jdbcdrive);
            conn = DriverManager.getConnection(url,username,userpassword);
            String sql = "update emp set ename = 'JERY',sal = ? where empno = ?";
            ps = conn.prepareStatement(sql);
            ps.setObject(1,sal);
            ps.setObject(2,m);
            int num = ps.executeUpdate();
            if (num>0){
                System.out.println("成功");

            }else {
                System.out.println("失败");
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally{
            try {
                ps.close();
                conn.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
